package com.koron.order.linepatrol.nopatrol.service.impl;


import com.koron.order.linepatrol.nopatrol.bean.po.LineNoPatrolPoint;
import com.koron.order.linepatrol.nopatrol.mapper.LineNoPatrolPointMapper;
import com.koron.order.linepatrol.nopatrol.service.LineNoPatrolPointService;
import org.apache.commons.collections4.CollectionUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 不巡视点(LineNoPatrolPoint)表服务实现类
 *
 * @author jzp
 * @since 2022-11-30 11:49:32
 */
@Service
public class LineNoPatrolPointServiceImpl implements LineNoPatrolPointService {

    /**
     * 通过ID查询单条数据
     *
     */
    @Override
    @TaskAnnotation("getById")
    public LineNoPatrolPoint getById(SessionFactory factory, String id) {
        LineNoPatrolPointMapper mapper = factory.getMapper(LineNoPatrolPointMapper.class);
        return mapper.selectById(id);
    }

    /**
     * 查询所有数据
     *
     */
    @Override
    @TaskAnnotation("list")
    public List<LineNoPatrolPoint> list(SessionFactory factory, LineNoPatrolPoint lineNoPatrolPoint) {
        LineNoPatrolPointMapper mapper = factory.getMapper(LineNoPatrolPointMapper.class);
        return mapper.selectList(lineNoPatrolPoint);
    }

    @Override
    @TaskAnnotation("listByNoPatrolId")
    public List<LineNoPatrolPoint> listByNoPatrolId(SessionFactory factory, String noPatrolId) {
        LineNoPatrolPoint lineNoPatrolPoint = new LineNoPatrolPoint();
        lineNoPatrolPoint.setNoPatrolId(noPatrolId);
        return list(factory, lineNoPatrolPoint);
    }

    /**
     * 新增数据
     *
     */
    @Override
    @TaskAnnotation("save")
    public boolean save(SessionFactory factory, LineNoPatrolPoint lineNoPatrolPoint) {
        LineNoPatrolPointMapper mapper = factory.getMapper(LineNoPatrolPointMapper.class);
        return mapper.insertOrUpdate(lineNoPatrolPoint) > 0;
    }

    @Override
    @TaskAnnotation("saveBatch")
    public boolean saveBatch(SessionFactory factory, List<LineNoPatrolPoint> lists) {
        if (CollectionUtils.isEmpty(lists)) {
            return false;
        }
        LineNoPatrolPointMapper mapper = factory.getMapper(LineNoPatrolPointMapper.class);
        return mapper.insertOrUpdateBatch(lists) > 0;
    }

    /**
     * 修改数据
     *
     */
    @Override
    @TaskAnnotation("update")
    public boolean update(SessionFactory factory, LineNoPatrolPoint lineNoPatrolPoint) {
        LineNoPatrolPointMapper mapper = factory.getMapper(LineNoPatrolPointMapper.class);
        return mapper.update(lineNoPatrolPoint) > 0;
    }

    /**
     * 通过主键删除数据
     *
     */
    @Override
    @TaskAnnotation("deleteById")
    public boolean deleteById(SessionFactory factory, String id) {
        LineNoPatrolPointMapper mapper = factory.getMapper(LineNoPatrolPointMapper.class);
        return mapper.hidden(id) > 0;
    }

    /**
     * 通过主键删除数据
     */
    @Override
    @TaskAnnotation("deleteBatchIds")
    public boolean deleteBatchIds(SessionFactory factory, List<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        LineNoPatrolPointMapper mapper = factory.getMapper(LineNoPatrolPointMapper.class);
        return mapper.deleteBatchIds(ids) > 0;
    }

    @Override
    @TaskAnnotation("removeByNoPatrolId")
    public boolean removeByNoPatrolId(SessionFactory factory, String noPatrolId) {
        if (StringUtils.isEmpty(noPatrolId)) {
            return false;
        }
        List<LineNoPatrolPoint> pointList = listByNoPatrolId(factory, noPatrolId);
        return deleteBatchIds(factory, pointList.stream().map(LineNoPatrolPoint::getId).collect(Collectors.toList()));

    }
}
